package com.kotlin.sample.grammar

import org.junit.jupiter.api.Test

class _1GrammarTest {

    @Test
    fun testGrammar01() {
        var a = 1
        // 模板中的简单名称：
        val s1 = "a is $a"
        println(s1)

        a = 2
        // 模板中的任意表达式：
        val s2 = "${s1.replace("is", "was")}, but now is $a"
        println(s2)
    }

    @Test
    fun testGrammar02() {
        val i = 10
        val s = "i = $i" // 求值结果为 "i = 10"
        println(s)
    }

    @Test
    fun testGrammar03() {
        val person = Bean02()
        println(person.name) // 输出 "initial value"
        person.name = ""
        println(person.name) // 仍然输出 "initial value"
        person.name = "John"
        println(person.name) // 输出 "John"
        person.name = ""
        println(person.name) // 仍然输出 "John"
    }
}